package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 工单节点状态
 * @author haibin.zhang
 */
@Getter
public enum WorkOrderNodeStatusEnum {
    /**
     *
     */
    UNACCEPTED(1,"","enum.workOrderNodeStatus.name.unaccepted"),


    ONGOING(2,"","enum.workOrderNodeStatus.name.ongoing"),


    FINISH(3,"","enum.workOrderNodeStatus.name.finish"),


    CLOSE(4,"","enum.workOrderNodeStatus.name.close"),


    ROLLBACK(5,"","enum.workOrderNodeStatus.name.rollback"),


    TRANSFERRED(6,"","enum.workOrderNodeStatus.name.transferred"),


    RESTART(100,"","enum.workOrderNodeStatus.name.restart"),
    UNKNOWN(404, "unknown","enum.callLogResult.name.unknown");

    private int code;
    private String alias;
    private String name;

    WorkOrderNodeStatusEnum(int code, String alias, String name){
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return WxErrorCodeEnum
     */
    public static WorkOrderNodeStatusEnum getByCode(Integer code) {
        for (WorkOrderNodeStatusEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<WorkOrderStatusEnum>
     */
    public static List<WorkOrderNodeStatusEnum> getAllEnum() {
        List<WorkOrderNodeStatusEnum> list = new ArrayList<>();
        for (WorkOrderNodeStatusEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取需要的枚举
     * @return List<WorkOrderStatusEnum>
     */
    public static List<WorkOrderNodeStatusEnum> getNeedEnum() {
        List<WorkOrderNodeStatusEnum> list = new ArrayList<>();
        for (WorkOrderNodeStatusEnum cache : values()) {
            if (cache.getCode() < 10) {
                list.add(cache);
            }
        }
        return list;
    }

    /**
     * Description: 获取name
     * @param code
     * @param defaultName
     * @author 刘阳
     * @date 2019/6/4 3:19 PM
     * @since v1.0
     */
    public static String getNameByCode(Integer code, String defaultName) {
        for (WorkOrderNodeStatusEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getCode(), code)) {
                defaultName = cacheCode.getName();
            }
        }
        return defaultName;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
